package com.example.b_308.myapplication.view.user.register;

import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;


import com.example.b_308.myapplication.comment.utils.StringValidator;
import com.example.b_308.myapplication.controller.UserController;
import com.example.b_308.myapplication.model.Staff;
import com.example.b_308.myapplication.view.base.BaseFragment;
import com.example.b_308.myapplication.view.user.login.IUserView;

/**
 * Created by B-308 on 2017/11/23.
 */
public class VerifyNewPasswordFragment extends BaseFragment implements View.OnClickListener, IUserView {
    UserController userController;
    EditText et_reg_password, et_reg_password_vertify;
    ImageView iv_look_password, iv_look_password_vertify;
    Button btn_complete;


    @Override
    protected void init() {
        userController = new UserController(this);
        btn_complete = findViewById(R.id.btn_complete);
        et_reg_password = findViewById(R.id.et_reg_password);
        et_reg_password_vertify = findViewById(R.id.et_reg_password_vertify);
        iv_look_password = findViewById(R.id.iv_look_password);
        iv_look_password_vertify = findViewById(R.id.iv_look_password_vertify);
        btn_complete.setOnClickListener(this);
        iv_look_password.setOnClickListener(this);
        iv_look_password_vertify.setOnClickListener(this);
        et_reg_password_vertify.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(et_reg_password.length() == 0){
                    btn_complete.setSelected(false);
                }else{
                    btn_complete.setSelected(true);
                }

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    @Override
    protected View setContentView(LayoutInflater inflater) {
        return inflater.inflate(R.layout.fragment_verity_new_password, null, false);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_complete:
                if (StringValidator.isSimiller(et_reg_password.getText().toString(), et_reg_password_vertify.getText().toString())) {
                    ((RegisterActivity) getActivity()).next(this, et_reg_password.getText().toString());
                } else {
                    fail("密码与确认密码不一致！！");
                }

                break;
            case R.id.iv_look_password:
                if (!iv_look_password.isSelected()) {
                    iv_look_password.setSelected(true);
                    et_reg_password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                } else {
                    iv_look_password.setSelected(false);
                    et_reg_password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT);
                }
                break;
            case R.id.iv_look_password_vertify:
                if (!iv_look_password_vertify.isSelected()) {
                    iv_look_password_vertify.setSelected(true);
                    et_reg_password_vertify.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                } else {
                    iv_look_password_vertify.setSelected(false);
                    et_reg_password_vertify.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT);
                }
                break;
        }
    }

    @Override
    public void loginSuccess(Staff staff) {

    }

    @Override
    public void registerSuccess() {

    }

    @Override
    public void getCodeSuccess() {

    }
}
